<?php
	
	App::import('Vendor', 'oauth');
	//require_once '../../src/contrib/apiCalendarService.php';
	//App::import('Vendor', 'apiCalendarService', array('file' =>'google_api_php'.DS.'contrib'.DS.'apiCalendarService.php'));
	class Gtask extends GapiAppModel {
		var $defaultParams = array();

		function taskList($params=NULL){
			$feed = 'https://www.googleapis.com/tasks/v1/users/@me/lists';
			$params = array_merge($this->defaultParams,$params);
			$result = $this->request('GET',$feed,$params);
			return $result;
		}
		
		function listTask($params=NULL){
			$feed = 'https://www.googleapis.com/tasks/v1/lists/@default/tasks';
			$params = array_merge($this->defaultParams,$params);
			$result = $this->request('GET',$feed,$params);
			return $result;
		}
		
		function addTask($params=NULL,$task){
			$feed = 'https://www.googleapis.com/tasks/v1/lists/@default/tasks';
			$params = array_merge($this->defaultParams,$params);
			$body = $this->getAddRequestBody($task);
			$result = $this->request('POST',$feed,$params,$body);
			//debug($result);
			return $result;
		}
		
		function getAddRequestBody($title){
			$body = array(
				'title'=>$title
			);
			$request_body = json_encode($body);
			//debug($request_body);
			return $request_body;
		}
		
		function updateTask($params=NULL,$gid,$link,$status){
			//$feed = 'https://www.googleapis.com/tasks/v1/lists/@default/tasks';
			$params = array_merge($this->defaultParams,$params);
			$body = $this->getUpdateRequestBody($gid,$status);
			$result = $this->request('PUT',$link,$params,$body);
			return $result;
		}
		
		function getUpdateRequestBody($gid,$status){
			$body = array(
				'id'=>$gid,
				'status'=>$status
			);
			$request_body = json_encode($body);
			//debug($request_body);
			return $request_body;
		}
		
		function getStatus($params=NULL,$gid,$link){
			$result = $this->request('GET',$link,$params);
			return $result->status;
		}
	}
?>
